package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.LogisticInfo;
import com.ruoyi.order.service.ILogisticInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 当前物流信息管理Controller
 * 
 * @author lzp
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/system/delivery")
public class LogisticInfoController extends BaseController
{
    @Autowired
    private ILogisticInfoService logisticInfoService;

    /**
     * 查询当前物流信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(LogisticInfo logisticInfo)
    {
        startPage();
        List<LogisticInfo> list = logisticInfoService.selectLogisticInfoList(logisticInfo);
        return getDataTable(list);
    }

    /**
     * 导出当前物流信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:delivery:export')")
    @Log(title = "当前物流信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogisticInfo logisticInfo)
    {
        List<LogisticInfo> list = logisticInfoService.selectLogisticInfoList(logisticInfo);
        ExcelUtil<LogisticInfo> util = new ExcelUtil<LogisticInfo>(LogisticInfo.class);
        util.exportExcel(response, list, "当前物流信息管理数据");
    }

    /**
     * 获取当前物流信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:delivery:query')")
    @GetMapping(value = "/{logisticId}")
    public AjaxResult getInfo(@PathVariable("logisticId") Long logisticId)
    {
        return success(logisticInfoService.selectLogisticInfoByLogisticId(logisticId));
    }

    @GetMapping(value = "/delivery/{deliveryOrderNo}")
    public AjaxResult getDelivery(@PathVariable("deliveryOrderNo") String deliveryOrderNo)
    {
        return success(logisticInfoService.selectLogisticInfoByDeliveryOrderNo(deliveryOrderNo));
    }


    /**
     * 新增当前物流信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:delivery:add')")
    @Log(title = "当前物流信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LogisticInfo logisticInfo)
    {
        return toAjax(logisticInfoService.insertLogisticInfo(logisticInfo));
    }

    /**
     * 修改当前物流信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:delivery:edit')")
    @Log(title = "当前物流信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LogisticInfo logisticInfo)
    {
        return toAjax(logisticInfoService.updateLogisticInfo(logisticInfo));
    }

    /**
     * 删除当前物流信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:delivery:remove')")
    @Log(title = "当前物流信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logisticIds}")
    public AjaxResult remove(@PathVariable Long[] logisticIds)
    {
        return toAjax(logisticInfoService.deleteLogisticInfoByLogisticIds(logisticIds));
    }
}
